package com.sh.suhe.utildemos.utils;

import android.util.Log;

public class LogUtil {
    /**
     * 单行最大输出长度
     */
    private static final int SINGLELINE_MAX_LENGTH = 1000;
    public static void w(String tag, String s) {
        log(Log.WARN,tag,s);
    }

    public static void e(String tag, String s) {
        log(Log.ERROR,tag,s);
    }
    public static void d(String tag, String s) {
        log(Log.DEBUG,tag,s);
    }
    public static void i(String tag, String s) {
        log(Log.INFO,tag,s);
    }
    public static void log(int priority,String tag, String s){
        Log.println(priority,tag,s);
    }

    public static void longText(String tag, String prefix, String msg) {
        int start = 0;
        int end = SINGLELINE_MAX_LENGTH;
        int msg_difference = msg.length() - SINGLELINE_MAX_LENGTH;
        int index = 0;
        if (msg_difference > 0) {
            for (; ; ) {
                Log.i(tag, prefix + "{" + index++ + "}：" + msg.substring(start, end));
                start = end;
                end += SINGLELINE_MAX_LENGTH;
                if (end >= msg.length()) {
                    Log.i(tag, prefix + "{" + index + "}：" + msg.substring(start));
                    return;
                }
            }
        } else {
            Log.i(tag, prefix + msg);
        }
    }
}
